package com.ruoyi.web.controller.crm;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BsProvince;
import com.ruoyi.system.service.IBsProvinceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 省份设置Controller
 * 
 * @author ruoyi
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/system/province")
public class BsProvinceController extends BaseController
{
    @Autowired
    private IBsProvinceService bsProvinceService;

    /**
     * 查询省份设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:province:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsProvince bsProvince)
    {
        startPage();
        List<BsProvince> list = bsProvinceService.selectBsProvinceList(bsProvince);
        return getDataTable(list);
    }

    /**
     * 导出省份设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:province:export')")
    @Log(title = "省份设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BsProvince bsProvince)
    {
        List<BsProvince> list = bsProvinceService.selectBsProvinceList(bsProvince);
        ExcelUtil<BsProvince> util = new ExcelUtil<BsProvince>(BsProvince.class);
        return util.exportExcel(list, "province");
    }

    /**
     * 获取省份设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:province:query')")
    @GetMapping(value = "/{provinceId}")
    public AjaxResult getInfo(@PathVariable("provinceId") Long provinceId)
    {
        return AjaxResult.success(bsProvinceService.selectBsProvinceById(provinceId));
    }

    /**
     * 新增省份设置
     */
    @PreAuthorize("@ss.hasPermi('system:province:add')")
    @Log(title = "省份设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsProvince bsProvince)
    {
        return toAjax(bsProvinceService.insertBsProvince(bsProvince));
    }

    /**
     * 修改省份设置
     */
    @PreAuthorize("@ss.hasPermi('system:province:edit')")
    @Log(title = "省份设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsProvince bsProvince)
    {
        return toAjax(bsProvinceService.updateBsProvince(bsProvince));
    }

    /**
     * 删除省份设置
     */
    @PreAuthorize("@ss.hasPermi('system:province:remove')")
    @Log(title = "省份设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{provinceIds}")
    public AjaxResult remove(@PathVariable Long[] provinceIds)
    {
        return toAjax(bsProvinceService.deleteBsProvinceByIds(provinceIds));
    }
}
